// Created by LH on 2017/8/29.
//思路，外层加一圈0，着色外层

#include <iostream>
using namespace std;
int map[36][36];
int change[4][2] = {
        { 0,  1 },
        { 0,  -1 },
        { 1,  0 },
        { -1, 0 } };
int n;
void dfs(int x, int y)
{
    for (int t = 0; t < 4; t++)
    {
        int nx = x + change[t][0];
        int ny = y + change[t][1];
        if (nx >= 0 && nx <= n&&ny >= 0 && ny <= n&&map[nx][ny] == 0)
        {
            map[nx][ny] = 3;
            dfs(nx, ny);
        }
    }
    return;
}

int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= n; ++j)
        {
            cin >> map[i][j];
        }
    }
    dfs(0, 0);
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= n; ++j)
        {
            if (map[i][j] == 3)
                printf("0 ");
            else if (map[i][j] == 1)
                printf("1 ");
            else
                printf("2 ");
        }
        cout << endl;
    }
    return 0;
}